*==============================================================================
*==============================================================================
*=     File-Name:      LocalNewsElectionAdmin_Analysis.do                    == 
*=     Date:           05/13/2025                                            ==
*=     Author:         Murat Abus (muabus@syr.edu)                           ==
*=     Purpose:        Replicate analysis in Abus, Bai & Dunaway Paper       == 
*=     Input File 1:   SPAE_combined.dta                                     ==
*=     Input File 2:   CPS_Voter_Supplement.dta, EAVS2016.dta, EAVS2020.dta  ==
*=     Software:       Stata IC 16.1                                         ==
*=     Machine:        Lenovo ThinkPad E570                                  == 
*=     System:         Ubuntu 24.04.2 LTS / GNOME 46                         ==
*==============================================================================
*==============================================================================
clear
pwd
version 16.1
set more off

//set trace on
//display
                                                            
// Set the working directory to where the data files are located.


// This is the replication code for Abus, Bai and Dunaway (2025, Electoral Studies "Local News, Partisanship, and Perceptions about Election Administration)

// Making a Polarization Graph Using ANES Dataset
use "ANES_polarization.dta", replace

line Ownpartyfeeling Rivalpartyfeeling Year, yline(0 10 20 30 40 50 60 70 80) ylabel(0(10)80) xline(1996 2000 2004 2008 2012 2016 2020) xlabel(1996(4)2020)

graph save polarization.gph, replace
graph export polarization.svg, replace

//// MAP CODE (BI-VARIATE CHOROPLETH MAPS) FOR THE MAIN TEXT

// "bimap" is a user-contributed command developed by Asjad Naqvi. Normally, the updated versions are pushed onto SSC quite fast, but installing from Github allows the use of most recent version. Of course, it can also be installed from SSC.

net install bimap, from("https://raw.githubusercontent.com/asjadnaqvi/stata-bimap/main/installation/") replace

// ssc install bimap, replace // to install from SSC

// There are three packages needed for bimap to run.

ssc install spmap, replace
ssc install palettes, replace
ssc install colrspace, replace

// We also set our scheme, schemepack has many options of schemes to use.

ssc install schemepack, replace
set scheme white_tableau  

mkdir bimaps // creating a folder for the maps

// Bimaps for Polling Place Evaluation and Local News Coverage

unzipfile "tl_2016_us_county.zip", replace
spshape2dta tl_2016_us_county.shp, replace 

use "tl_2016_us_county.dta", clear
describe
destring _all, replace

drop if (STATEFP == 2) | (STATEFP == 60) | (STATEFP == 66) | (STATEFP == 69) | (STATEFP == 72) | (STATEFP == 78) | (STATEFP == 74) | (STATEFP == 15)  

save "tl_2016_us_county.dta", replace

use "tl_2016_us_county.dta", clear

spset // Defining as a spatial dataset
grmap // Checking if it is properly defined

// Newspaper Circulation and Polling Evaluation (2016)      
use "tl_2016_us_county.dta", clear

use "2016countydata.dta", replace
describe
destring _all, replace
save "2016countydata.dta", replace

merge 1:1 STATEFP COUNTYFP using tl_2016_us_county.dta
keep if _m==3
drop _m
geo2xy _CY _CX, proj(albers) replace

bimap avgeval per, shp(usa_county_shp_clean) cuty(0 3.3 3.8 4) /// 
cutx(0 0.02 0.06 1.5) formatx(%3.2f) formaty(%3.1f) palette(pinkgreen) ///
ndfcolor(gs14) title("2016", size(small)) textx("Newspaper Circulation") ///
texty("Polling Place Evaluation") texts(3.5) textlabs(3) percent /// 
lc() lw(none)  /// 
polygon(data("usa_state_shp_clean") ocolor(black) osize(0.1))

graph save bimaps/figure_2016_newspaper.gph, replace

// Newspaper Circulation and Polling Evlauation (2020)       
use "tl_2016_us_county.dta", clear

use "2020countydata.dta", replace
describe
destring _all, replace
save "2020countydata.dta", replace

merge 1:1 STATEFP COUNTYFP using tl_2016_us_county.dta
keep if _m==3
drop _m
geo2xy _CY _CX, proj(albers) replace

bimap avgeval per, shp(usa_county_shp_clean) cuty(0 3.3 3.8 4) /// 
cutx(0 0.02 0.06 1.5) formatx(%3.2f) formaty(%3.1f) palette(pinkgreen) ///
ndfcolor(gs14) title("2020", size(small)) textx("Newspaper Circulation") ///
texty("Polling Place Evaluation") texts(3.5) textlabs(3) percent /// 
lc() lw(none)  /// 
polygon(data("usa_state_shp_clean") ocolor(black) osize(0.1))

graph save bimaps/figure_2020_newspaper.gph, replace

// Now to combine these into one figure:

graph combine bimaps/figure_2016_newspaper.gph bimaps/figure_2020_newspaper.gph, rows(2) altshrink xsize(5) ysize(6)
 
graph save bimaps/figure2.gph, replace
graph export bimaps/figure2.svg, replace


// Bimaps for CEA Index and Polling Place Evaluations

// 2016 
use "tl_2016_us_county.dta", clear

use "2016countydata.dta", replace
describe
destring _all, replace
save "2016countydata.dta", replace

merge 1:1 STATEFP COUNTYFP using tl_2016_us_county.dta
keep if _m==3
drop _m
geo2xy _CY _CX, proj(albers) replace

bimap avgeval cea, shp(usa_county_shp_clean) cuty(0 3.3 3.8 4) cutx(25 45 65 85) palette(pinkgreen)  ///
ndfcolor(gs14) title("2016", size(small)) ///	
textx("CEA Index") texty("Polling Place Evaluation") texts(3.5) textlabs(3)  percent ///
lc() lw(none) ///
polygon(data("usa_state_shp_clean") ocolor(black) osize(0.1))

graph save bimaps/figure_2016_cea.gph, replace


// 2020

use "tl_2016_us_county.dta", clear

use "2020countydata.dta", replace
describe
destring _all, replace
save "2020countydata.dta", replace

merge 1:1 STATEFP COUNTYFP using tl_2016_us_county.dta
keep if _m==3
drop _m
geo2xy _CY _CX, proj(albers) replace

bimap avgeval cea, shp(usa_county_shp_clean) cuty(0 3.3 3.8 4) cutx(38 55 72 89) palette(pinkgreen)  ///
ndfcolor(gs14) title("2020", size(small)) ///	
textx("CEA Index") texty("Polling Place Evaluation") texts(3.5) textlabs(3)  percent ///
lc() lw(none) ///
polygon(data("usa_state_shp_clean") ocolor(black) osize(0.1))


graph save bimaps/figure_2020_cea.gph, replace

// Combining
graph combine bimaps/figure_2016_cea.gph bimaps/figure_2020_cea.gph, rows(2) altshrink xsize(5) ysize(6)
 
graph save bimaps/figure2_1.gph, replace
graph export bimaps/figure2_1.svg, replace

// Bimaps for CEA Index and Local News Coverage 

// 2016
use "tl_2016_us_county.dta", clear

use "2016countydata.dta", replace
describe
destring _all, replace
save "2016countydata.dta", replace
//keep if per18 <= 1.5 // dropping the outlier in newspaper circulation

merge 1:1 STATEFP COUNTYFP using tl_2016_us_county.dta
keep if _m==3
drop _m
geo2xy _CY _CX, proj(albers) replace

bimap cea per18, shp(usa_county_shp_clean) cutx(0 0.02 0.06 1.5) cuty(24 45 65 90) formatx(%3.2f) formaty(%3.0f) palette(pinkgreen) ndfcolor(gs14) title("2016", size(small))  ///	
textx("Newspaper Circulation") texty("CEA Index") texts(3.5) textlabs(3)  percent ///
lc() lw(none) ///
polygon(data("usa_state_shp_clean") ocolor(black) osize(0.1))

graph save bimaps/figure_2016_polling.gph, replace


//2020
use "tl_2016_us_county.dta", clear

use "2020countydata.dta", replace
describe
destring _all, replace
save "2020countydata.dta", replace
//keep if per18 <= 1.5 // dropping the outlier in newspaper circulation

merge 1:1 STATEFP COUNTYFP using tl_2016_us_county.dta
keep if _m==3
drop _m
geo2xy _CY _CX, proj(albers) replace

bimap cea per18, shp(usa_county_shp_clean) cutx(0 0.02 0.06 1.5) cuty(38 55 72 89) formatx(%3.2f) formaty(%3.0f) palette(pinkgreen) ndfcolor(gs14) title("2020", size(small))  ///	
textx("Newspaper Circulation") texty("CEA Index") texts(3.5) textlabs(3)  percent ///
lc() lw(none) ///
polygon(data("usa_state_shp_clean") ocolor(black) osize(0.1))

graph save bimaps/figure_2020_polling.gph, replace


// Combining 

graph combine bimaps/figure_2016_polling.gph bimaps/figure_2020_polling.gph, rows(2) altshrink xsize(5) ysize(6)
 
graph save bimaps/figure2_2.gph, replace
graph export bimaps/figure2_2.svg, replace


// END OF MAP CODE FOR MAIN TEXT


// CODE FOR MODELS IN THE MAIN TEXT

use "SPAE_combined.dta", clear

// Model 1 - Main Text
logit polplacelog per18daily cea ib3.pid3##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight], cluster(countyfips) 

eststo model1: quietly logit polplacelog per18daily cea ib3.pid3##c.votemargin age gender educ nowhite newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight], cluster(countyfips) 

// Model 2 - Main Text
logit polplacelog c.per18daily##c.cea ib3.pid3##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight], cluster(countyfips) 

eststo model2: quietly logit polplacelog c.per18daily##c.cea ib3.pid3##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight], cluster(countyfips) 

// Model 3 - Main Text (Low Local News Circulation)
logit polplacelog cea ib3.pid3##c.votemargin age gender educ nowhite newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight] if per18daily<.072, cluster(countyfips) 

eststo model3: quietly logit polplacelog cea ib3.pid3##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight] if per18daily<.072, cluster(countyfips)  

// Model 4 - Main Text (High Local News Circulation)
logit polplacelog cea ib3.pid3##c.votemargin age gender educ nowhite newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight] if per18daily>.12, cluster(countyfips) 

eststo model4: quietly logit polplacelog cea ib3.pid3##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight] if per18daily>.17, cluster(countyfips) 

// Printing the Combined Results Table (2008 -- 2020)
esttab model1 model2 model3 model4 using "table1.tex", replace b(%9.3g) se(%9.3g) label aic bic nogap nonumbers mtitle("I" "II" "III" "IV") title("Polling Place Evaluation, 2008--2020") star(* 0.1 ** 0.05 *** 0.01)


use "SPAE_combined.dta", clear

// MARGINAL EFFECTS PLOTS (MAIN TEXT)

// Figure 3 (Polling Place Evaluation, Newspaper Circulation, and CEA)

// Graph (CEA)
quietly logit polplacelog c.per18daily##c.cea ib3.pid3##c.votemargin age gender educ nowhite newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state year [pw=weight], cluster(countyfips)

qui margins, at(per18=(0(0.1)1) cea=(27))

marginsplot, recast(line) recastci(rarea) plotopts(lcolor(black) /// 
lwidth(thin) lpattern(solid)) ciopts(fcolor(black%30) lcolor(gs10)) xsize(3) ysize(3) ytitle("Predicted positive evaluation", size(small)) xtitle("Newspaper circulation per capita", size(small)) title("Low County Election Administration (CEA) Index", size(small)) 

graph save marginplots/figure3.gph, replace
graph export marginplots/figure3.pdf, replace
graph export marginplots/figure3.svg, replace


// Figure 4

set graphics off 

// Graph one 
quietly logit polplacelog per18daily cea ib3.pid3##c.votemargin age gender educ nowhite newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight], cluster(countyfips) 

margins, at(pid3=(1) votemargin=(-50(5)50))

marginsplot, recast(line) recastci(rarea) plotopts(lcolor(black) /// 
lwidth(thin) lpattern(solid)) ciopts(fcolor(black%30) lcolor(gs10)) xsize(2) ysize(2) xlabel(-50(10)50) ytitle("") title("Base model", size(small)) xtitle("GOP vote margin", size(small))

graph save marginplots/margin1.gph, replace

// Graph two 
quietly logit polplacelog cea ib3.pid3##c.votemargin age gender educ nowhite newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight]if per18daily<.072, cluster(countyfips) 

margins, at(pid3=(1) votemargin=(-50(5)50))

marginsplot, recast(line) recastci(rarea) plotopts(lcolor(black) /// 
lwidth(thin) lpattern(solid)) ciopts(fcolor(black%30) lcolor(gs10)) xsize(2) ysize(2) xlabel(-50(10)50) ytitle("") title("Low newspaper circulation", size(small)) xtitle("GOP vote margin", size(small))

graph save marginplots/margin2.gph, replace

// Graph three
quietly logit polplacelog cea ib3.pid3##c.votemargin age gender educ nowhite newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight] if per18daily>.17, cluster(countyfips) 

margins, at(pid3=(1) votemargin=(-50(5)50))

marginsplot, recast(line) recastci(rarea) plotopts(lcolor(black) /// 
lwidth(thin) lpattern(solid)) ciopts(fcolor(black%30) lcolor(gs10)) xsize(2) ysize(2) xlabel(-50(10)50) ytitle("") title("High newspaper circulation", size(small)) xtitle("GOP vote margin", size(small))

graph save marginplots/margin3.gph, replace

graph combine marginplots/margin1.gph marginplots/margin2.gph marginplots/margin3.gph, ycommon cols(3) title("DEMOCRATS", size(small)) 

graph save marginplots/figure41.gph, replace 
graph export marginplots/figure41.pdf, replace
graph export marginplots/figure41.svg, replace

// Graph four
quietly logit polplacelog per18daily cea ib3.pid3##c.votemargin age gender educ nowhite newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight], cluster(countyfips) 

margins, at(pid3=(2) votemargin=(-50(5)50))

marginsplot, recast(line) recastci(rarea) plotopts(lcolor(black) /// 
lwidth(thin) lpattern(solid)) ciopts(fcolor(black%30) lcolor(gs10)) xsize(2) ysize(2) xlabel(-50(10)50) ytitle("") title("Base model", size(small)) xtitle("GOP vote margin", size(small))

graph save marginplots/margin4.gph, replace

// Graph five:
quietly logit polplacelog cea ib3.pid3##c.votemargin age gender educ nowhite newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight] if per18daily<.072, cluster(countyfips) 

margins, at(pid3=(2) votemargin=(-50(5)50))

marginsplot, recast(line) recastci(rarea) plotopts(lcolor(black) /// 
lwidth(thin) lpattern(solid)) ciopts(fcolor(black%30) lcolor(gs10)) xsize(2) ysize(2) xlabel(-50(10)50) ytitle("") title("Low newspaper circulation", size(small)) xtitle("GOP vote margin", size(small))

graph save marginplots/margin5.gph, replace

// Graph six:
quietly logit polplacelog cea ib3.pid3##c.votemargin age gender educ nowhite newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight] if per18daily>.17, cluster(countyfips) 

margins, at(pid3=(2) votemargin=(-50(5)50))

marginsplot, recast(line) recastci(rarea) plotopts(lcolor(black) /// 
lwidth(thin) lpattern(solid)) ciopts(fcolor(black%30) lcolor(gs10)) xsize(2) ysize(2) xlabel(-50(10)50) ytitle("") title("High newspaper circulation", size(small)) xtitle("GOP vote margin", size(small))

graph save marginplots/margin6.gph, replace

graph combine marginplots/margin4.gph marginplots/margin5.gph marginplots/margin6.gph, ycommon cols(3) title("REPUBLICANS", size(small)) 

graph save marginplots/figure42.gph, replace 
graph export marginplots/figure42.pdf, replace
graph export marginplots/figure42.svg, replace

set graphics on

// Generating Figure 4 in the Text:
graph combine marginplots/figure41.gph marginplots/figure42.gph, imargin(0 0 0 0) rows(2) xsize(5) ysize(4) l1(Predicted Positive Evaluation, size(small))  

graph save marginplots/figure4.gph, replace 
graph export marginplots/figure4.pdf, replace
graph export marginplots/figure4.svg, replace


**************** END OF CODE FOR THE MAIN TEXT*******************************

*************** APPENDIX MODELS, TABLES, MAPS, and GRAPHS********************

// MAP CODE CHOROPLETH MAPS 
//Appendix A

mkdir appendixmaps // Creating a folder for the appendix maps
set graphics off

// Maps for 2016
use "tl_2016_us_county.dta", clear
use "2016countydata.dta", replace

merge 1:1 STATEFP COUNTYFP using tl_2016_us_county.dta
keep if _m==3
drop _m
geo2xy _CY _CX, proj(albers) replace

spmap per using usa_county_shp_clean, id(_ID) clm(custom) clnumber(7) ///
clbreaks(0 0.02 0.06 0.08 0.1 0.5 1.5) fcolor(Blues2) ndfcolor(gs14) ///
ndlabel("Not in sample") legtitle("Newspaper Circulation") legcount

graph save appendixmaps/figure1.gph, replace
graph export appendixmaps/figure1.svg, replace

spmap margin using usa_county_shp_clean, id(_ID) clmethod(eqint) ///
fcolor(BuYlRd) ndfcolor(gs14) ///
ndlabel("Not in sample") legtitle("Republican Vote Margin") legcount

graph save appendixmaps/figure3.gph, replace
graph export appendixmaps/figure3.svg, replace

spmap avgeval using usa_county_shp_clean, id(_ID) clm(custom) clnumber(6) ///
clbreaks(2 2.5 3 3.5 3.75 4) fcolor(Greens2) ndfcolor(gs14) ///
ndlabel("Not in sample") legtitle("Polling Place Evaluation") legcount

graph save appendixmaps/figure5.gph, replace
graph export appendixmaps/figure5.svg, replace

spmap cea using usa_county_shp_clean, id(_ID) clm(custom) clnumber(10) ///
clbreaks(0 20 30 40 50 60 70 80 90 100) fcolor(YlGn) ndfcolor(gs14) ///
ndlabel("Not in sample") legtitle("County election admin. index") legcount

graph save appendixmaps/figure7.gph, replace
graph export appendixmaps/figure7.svg, replace

// Maps for 2020
use "tl_2016_us_county.dta", clear
use "2020countydata.dta", replace

merge 1:1 STATEFP COUNTYFP using tl_2016_us_county.dta
keep if _m==3
drop _m
geo2xy _CY _CX, proj(albers) replace

spmap per using usa_county_shp_clean, id(_ID) clm(custom) clnumber(7) ///
clbreaks(0 0.02 0.06 0.08 0.1 0.5 1.5) fcolor(Blues2) ndfcolor(gs14) ///
ndlabel("Not in sample") legtitle("Newspaper Circulation") legcount

graph save appendixmaps/figure2.gph, replace
graph export appendixmaps/figure2.svg, replace

spmap margin using usa_county_shp_clean, id(_ID) clmethod(eqint) ///
fcolor(BuYlRd) ndfcolor(gs14) ///
ndlabel("Not in sample") legtitle("Republican Vote Margin") legcount

graph save appendixmaps/figure4.gph, replace
graph export appendixmaps/figure4.svg, replace

spmap avgeval using usa_county_shp_clean, id(_ID) clm(custom) clnumber(6) ///
clbreaks(2 2.5 3 3.5 3.75 4) fcolor(Greens2) ndfcolor(gs14) ///
ndlabel("Not in sample") legtitle("Polling Place Evaluation") legcount

graph save appendixmaps/figure6.gph, replace
graph export appendixmaps/figure6.svg, replace

spmap cea using usa_county_shp_clean, id(_ID) clm(custom) clnumber(10) ///
clbreaks(0 20 30 40 50 60 70 80 90 100) fcolor(YlGn) ndfcolor(gs14) ///
ndlabel("Not in sample") legtitle("County election admin. index") legcount

graph save appendixmaps/figure8.gph, replace
graph export appendixmaps/figure8.svg, replace

// Mapping Elections Performance Index (State Level)
unzipfile "cb_2018_us_state_500k.zip", replace
spshape2dta cb_2018_us_state_500k.shp, replace 

use "cb_2018_us_state_500k.dta", clear
describe
destring _all, replace

drop if (STATEFP == 2) | (STATEFP == 60) | (STATEFP == 66) | (STATEFP == 69) | (STATEFP == 72) | (STATEFP == 78) | (STATEFP == 74) | (STATEFP == 15)  

save "cb_2018_us_state_500k.dta", replace

use "cb_2018_us_state_500k.dta", clear

spset // Defining as a spatial dataset
grmap // Checking if it is properly defined

use "cb_2018_us_state_500k.dta", clear
use "epi.dta", replace

merge 1:1 STATEFP using cb_2018_us_state_500k.dta
keep if _m==3
drop _m
geo2xy _CY _CX, proj(albers) replace

local murat epi08 epi12 epi16 epi20

foreach i of local murat{
spmap `i' using usa_state_shp_clean, id(_ID) clm(custom) clnumber(9) ///
clbreaks(0 .3 .4 .5 .6 .7 .8 .9 1) fcolor(OrRd) ndfcolor(white) ///
ndlabel("Not in sample") legtitle("Elections performance index") legcount

graph save appendixmaps/figure_`i'.gph, replace
graph export appendixmaps/figure_`i'.svg, replace

}


// End of Map Code for the (Appendix A)

// CODE FOR ROBUSTNESS CHECKS IN THE APPENDIX

use "SPAE_combined.dta", clear

// Appendix B (Original Coding of the Dependent Variable)

// Model 1
ologit polplaceeval per18daily cea ib3.pid3##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight], cluster(countyfips) 

eststo modelapp1: quietly ologit polplaceeval per18daily cea ib3.pid3##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight], cluster(countyfips) 

// Model 2 
ologit polplaceeval c.per18daily##c.cea ib3.pid3##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight], cluster(countyfips) 

eststo modelapp2: quietly ologit polplaceeval c.per18daily##c.cea ib3.pid3##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight], cluster(countyfips) 

// Model 3 (Low Local News Circulation)
ologit polplaceeval cea ib3.pid3##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight] if per18daily<.072, cluster(countyfips) 

eststo modelapp3: quietly ologit polplaceeval cea ib3.pid3##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight] if per18daily<.072, cluster(countyfips) 

// Model 4 (High Local News Circulation)
ologit polplaceeval cea ib3.pid3##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight] if per18daily>.12, cluster(countyfips) 

eststo modelapp4: quietly ologit polplaceeval cea ib3.pid3##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight] if per18daily>.12, cluster(countyfips) 

// Printing the Combined Results Table (2016 -- 2020)
esttab modelapp1 modelapp2 modelapp3 modelapp4 using "apptable1.tex", replace b(%9.3g) se(%9.3g) label aic bic nogap nonumbers mtitle("I" "II" "III" "IV") title("Polling Place Evaluation, 2008--2020") star(* 0.1 ** 0.05 *** 0.01)

// Appendix C (Alternative Specifications)
use "SPAE_combined.dta", clear

// Model 1 
logit polplacelog per18daily cea c.pid5##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight], cluster(countyfips) 

eststo modelapp5: quietly logit polplacelog per18daily cea c.pid5##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight], cluster(countyfips) 

// Model 2 
logit polplacelog c.per18daily##c.cea c.ideo5##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight], cluster(countyfips) 

eststo modelapp6: quietly logit polplacelog c.per18daily##c.cea c.ideo5##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight], cluster(countyfips) 

// Model 3 (Low Local News Circulation)
logit polplacelog cea ib3.pid5##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight] if per18daily<.072, cluster(countyfips) 

eststo modelapp7: quietly logit polplacelog cea ib3.pid5##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight] if per18daily<.072, cluster(countyfips) 

// Model 4 (High Local News Circulation)
logit polplacelog cea ib3.pid5##c.votemargin age gender educ nowhite newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight] if per18daily>.12, cluster(countyfips) 

eststo modelapp8: quietly logit polplacelog cea ib3.pid5##c.votemargin age gender educ nowhite newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight] if per18daily>.12, cluster(countyfips) 

// Printing the Combined Results Table (2016 -- 2020)
esttab modelapp5 modelapp6 modelapp7 modelapp8 using "apptable2.tex", replace b(%9.3g) se(%9.3g) label aic bic nogap nonumbers mtitle("I" "II" "III" "IV") title("Polling Place Evaluation, 2008--2020") star(* 0.1 ** 0.05 *** 0.01)


// Appendix D (Multi-level Model) 
use "SPAE_combined.dta", clear

// Model 1 
melogit polplacelog per18daily cea ib3.pid3##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight] || countyfips: 

eststo modelapp9: quietly melogit polplacelog per18daily cea ib3.pid3##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight] || countyfips: 

// Model 2 
melogit polplacelog c.per18daily##c.cea ib3.pid3##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight] || countyfips: 

eststo modelapp10: quietly melogit polplacelog c.per18daily##c.cea ib3.pid3##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight] || countyfips: 

// Model 3 (Low Local News Circulation)
melogit polplacelog cea ib3.pid3##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight] if per18daily<.072 || countyfips: 

eststo modelapp11: quietly melogit polplacelog cea ib3.pid3##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight] if per18daily<.072 || countyfips: 

// Model 4 (High Local News Circulation)
melogit polplacelog cea ib3.pid3##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight] if per18daily>.121 || countyfips: 

eststo modelapp12: quietly melogit polplacelog cea ib3.pid3##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight] if per18daily>.121 || countyfips: 

// Printing the Combined Results Table (2016 -- 2020)
esttab modelapp9 modelapp10 modelapp11 modelapp12 using "apptable3.tex", replace b(%9.3g) se(%9.3g) label aic bic nogap nonumbers mtitle("I" "II" "III" "IV") title("Polling Place Evaluation, 2008--2020") star(* 0.1 ** 0.05 *** 0.01)

// Appendix E (Substituting EPI for CEA Index)
use "SPAE_combined.dta", clear

// Model 1 
logit polplacelog per18daily epi ib3.pid3##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight], cluster(countyfips) 

eststo modelapp13: quietly logit polplacelog per18daily epi ib3.pid3##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight], cluster(countyfips) 

// Model 2 
logit polplacelog c.per18daily##c.epi ib3.pid3##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight], cluster(countyfips) 

eststo modelapp14: quietly logit polplacelog c.per18daily##c.epi ib3.pid3##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight], cluster(countyfips) 

// Model 3 (Low Local News Circulation)
logit polplacelog epi ib3.pid3##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight] if per18daily<.072, cluster(countyfips) 

eststo modelapp15: quietly logit polplacelog epi ib3.pid3##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight] if per18daily<.072, cluster(countyfips)  

// Model 4 (High Local News Circulation)
logit polplacelog epi ib3.pid3##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight] if per18daily>.121, cluster(countyfips) 

eststo modelapp16: quietly logit polplacelog epi ib3.pid3##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight] if per18daily>.12, cluster(countyfips) 

// Printing the Combined Results Table (2016 -- 2020)
esttab modelapp13 modelapp14 modelapp15 modelapp16 using "apptable4.tex", replace b(%9.3g) se(%9.3g) label aic bic nogap nonumbers mtitle("I" "II" "III" "IV") title("Polling Place Evaluation, 2008--2020") star(* 0.1 ** 0.05 *** 0.01)


// Appendix F ("Voting Experiences Index" as a Dependent Variable)
use "SPAE_combined.dta", clear

// Model 1 
reg index per18daily cea ib3.pid3##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight], cluster(countyfips) 

eststo modelapp17: quietly reg index per18daily cea ib3.pid3##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight], cluster(countyfips) 

// Model 2 
reg index c.per18daily##c.cea ib3.pid3##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight], cluster(countyfips) 

eststo modelapp18: quietly reg index c.per18daily##c.cea ib3.pid3##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight], cluster(countyfips) 

// Model 3 (Low Local News Circulation)
reg index cea ib3.pid3##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight] if per18daily<.072, cluster(countyfips) 

eststo modelapp19: quietly reg index cea ib3.pid3##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight] if per18daily<.072, cluster(countyfips) 

// Model 4 (High Local News Circulation)
reg index cea ib3.pid3##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight] if per18daily>.121, cluster(countyfips) 

eststo modelapp20: quietly reg index cea ib3.pid3##c.votemargin age gender educ nowhite  newsint perc_minor logmedhhinc i.pew_rur_code precpop_ln ib1.state i.year [pw=weight] if per18daily>.121, cluster(countyfips) 

// Printing the Combined Results Table (2016 -- 2020)
esttab modelapp17 modelapp18 modelapp19 modelapp20 using "apptable5.tex", replace b(%9.3g) se(%9.3g) label r2 nogap nonumbers mtitle("I" "II" "III" "IV") title("Polling Place Evaluation, 2008--2020") star(* 0.1 ** 0.05 *** 0.01)

 
// Appendix J (Descriptive Statistics)  
summ polplacelog polplaceeval per18daily cea epi pid3 pid5 votemargin age gender educ nowhite newsint perc_minor medhhinc pew_rur_code precpop index
  
  
********END OF CODE FOR APPENDIX TABLES, MAPS, and GRAPHS*******************
*********************END OF DO-FILE ****************************************

